<!-- 查询骑手分配订单 -->
<template>
    <div >
        <div class='table-page-search-wrapper'>
            <a-form layout='inline'>
               <a-row :gutter='48'>
                    <a-col :md="8">
                        <a-form-item label="手机号">
                            <a-input v-model="phone" allow-clear placeholder="请输入手机号" />
                        </a-form-item>
                    </a-col>
                    <a-col :md="8">
                        <a-form-item label="姓名">
                            <a-input v-model="name" allow-clear placeholder="请输入姓名" />
                        </a-form-item>
                    </a-col>
                    <a-col :md='8' :sm='24'>
                        <a-form-item >
                            <a-button type='primary' @click="getData">查询</a-button>
                            <a-button style="margin-left: 20px" type="" icon="plus" @click="add()">新增</a-button>
                        </a-form-item>
                    </a-col>
                </a-row>
            </a-form>
        </div>  
        <a-table rowKey="id" :loading="isload" :columns="columns" :data-source="dataList" @change="handleTableChange" :pagination="{ pageSize: size, total: total ,showSizeChanger: true}" size="small">
            <template slot="operation" slot-scope="text, record">
                <div class="editable-row-operations">
                    <a-button type="link" @click="update(record)">修改</a-button>
                    <a-popconfirm
                        title="是否确认删除当前骑手信息?"
                        ok-text="Yes"
                        cancel-text="No"
                        @confirm="del(record)"
                    >
                        <a-button type="link" class="errorColor" >删除</a-button>
                    </a-popconfirm>
                </div>
            </template>
        </a-table>

        <!-- 添加骑手信息 -->
        <a-modal
            title="添加、修改骑手信息"
            :visible="visible"
            :confirm-loading="confirmLoading"
            @ok="handleOk"
            @cancel="visible = false"
            >
            <div>
                <a-form :label-col="{ span: 6 }" :wrapper-col="{ span: 17 }">
                    <a-form-item label="骑手姓名" >
                        <a-input v-model="item.name" placeholder="请输入骑手姓名" allow-clear></a-input>
                    </a-form-item>
                    <a-form-item label="骑手手机号">
                        <a-input v-model="item.phone" placeholder="请输入骑手手机号" allow-clear></a-input>
                    </a-form-item>
                </a-form>
            </div>
        </a-modal>
    </div>
</template>

<script>
import { columns } from './table';
import { queryRiderUserInfo , updateRiderUserInfo } from '@/api/newMall';
export default {
    data () {
        return {
            brandId: this.global.brandId,
            phone: '',
            name: '', // 姓名
            page: 1,
            size: 10,
            total: 0,
            dataList: [],
            columns,
            colors: ['blue','purple','cyan','green','orange','red','pink','brown','indigo','lime','purple','teal','yellow','amber'],
            isload: false,
            item: {
                id: '',
                name: '',
                phone: '',
            },
            confirmLoading: false,
            isload: false,
            visible: false,
        };
    },
    created(){
        this.getData();
    },
    methods: {
        getData(){
            let _this = this
            const params = {
                'brandId': _this.brandId,
                'phone': _this.phone,
                'name': _this.name,
                'size':_this.size,
                'page':_this.page - 1,
            }
            _this.isload = true
            queryRiderUserInfo(params)
            .then(res=>{
                _this.isload = false;
                if(res.success){
                    console.log(res,'res')
                    _this.dataList = res.data.content
                    _this.total = res.data.data.totalElements;
                }else{
                    _this.$notification['error']({
                        message: '提示',
                        description: res.errMessage,
                        duration: 8,
                    })
                }
            })
        },
        // 分页
        handleTableChange(pagination, filters, sorter) {
            console.log(pagination);
            this.page = pagination.current;
            this.size = pagination.pageSize;
            this.getData()
        },
        // 添加
        add(){
            if(!this.brandId){
                this.$message.warning('请先选择品牌')
                return
            }
            this.item.id = ''
            this.item.brandId = this.brandId
            this.item.name = ''
            this.item.phone = ''
            this.visible = true
        },
        // 修改
        update(item){
            let _this = this;
            _this.item = JSON.parse(JSON.stringify(item))
            _this.visible = true
        },
        // 确定添加、修改
        handleOk(){
            let _this = this
            if(_this.item.name == ''){
                this.$message.warning('请输入骑手姓名');
                return
            }
            if(_this.item.phone == ''){
                this.$message.warning('请输入骑手手机号');
                return
            }
            _this.confirmLoading = true
            const params = {
                'id':_this.item.id,
                'brandId':_this.brandId,
                'name':_this.item.name,
                'phone':_this.item.phone,
            }
            updateRiderUserInfo(params)
            .then(res=>{
                _this.confirmLoading = false
                if(res.success){
                    _this.$notification['success']({
                        message: '提示',
                        description: _this.item.id == '' ? '添加成功' : '修改成功',
                        duration: 8,
                    })
                    _this.visible = false
                    _this.getData()
                }else{
                    _this.$notification['error']({
                        message: '提示',
                        description: res.errMessage,
                        duration: 8,
                    })
                }
            })
        },
        // 删除
        del(item){
            let _this = this
            const params = {
                'brandId':item.brandId,
                'id':item.id,
                'isDelete':1,
            }
            updateRiderUserInfo(params)
            .then(res=>{
                if(res.success){
                    _this.visible = false
                    _this.getData()
                    _this.$notification['success']({
                        message: '提示',
                        description: '删除成功',
                        duration: 8,
                    })
                }else{
                    _this.$notification['error']({
                        message: '提示',
                        description: res.errMessage,
                        duration: 8,
                    })
                }
            })
        },
    }
}

</script>
<style scoped>
</style>